using System;
namespace APP.HELPER.Utils.BarcodeLib
{
	internal class Postnet : BarcodeCommon, IBarcode
	{
		private string[] POSTNET_Code = new string[]
		{
			"11000",
			"00011",
			"00101",
			"00110",
			"01001",
			"01010",
			"01100",
			"10001",
			"10010",
			"10100"
		};
		public string Encoded_Value
		{
			get
			{
				return this.Encode_Postnet();
			}
		}
		public Postnet(string input)
		{
			this.Raw_Data = input;
		}
		private string Encode_Postnet()
		{
			this.Raw_Data = this.Raw_Data.Replace("-", "");
			switch (this.Raw_Data.Length)
			{
			case 5:
			case 6:
			case 9:
			case 11:
			{
				string text = "1";
				int num = 0;
				string raw_Data = this.Raw_Data;
				for (int i = 0; i < raw_Data.Length; i++)
				{
					char c = raw_Data[i];
					try
					{
						int num2 = Convert.ToInt32(c.ToString());
						text += this.POSTNET_Code[num2];
						num += num2;
					}
					catch (Exception ex)
					{
						throw new Exception("EPOSTNET-2: Invalid data. (Numeric only) --> " + ex.Message);
					}
				}
				int num3 = num % 10;
				int num4 = 10 - ((num3 == 0) ? 10 : num3);
				text += this.POSTNET_Code[num4];
				text += "1";
				return text;
			}
			}
			throw new Exception("EPOSTNET-2: Invalid data length. (5, 6, 9, or 11 digits only)");
		}
	}
}
